package cn.com.hp.feature.controller;

import cn.com.hp.feature.domain.dto.MenuInfoDTO;
import cn.com.hp.feature.domain.dto.SysUserInfoDTO;
import cn.com.hp.feature.domain.entity.MenuInfo;
import cn.com.hp.feature.domain.entity.SysUserInfo;
import cn.com.hp.feature.domain.vo.MenuInfoVO;
import cn.com.hp.feature.domain.vo.PageVO;
import cn.com.hp.feature.domain.vo.SysUserInfoVO;
import cn.com.hp.feature.response.BaseResponse;
import cn.com.hp.feature.response.BaseResponseStatus;
import cn.com.hp.feature.service.IMenuInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: hjz
 * @since: 2022/8/29
 * @description:
 */
@RestController
@AllArgsConstructor
@RequestMapping("/menu")
@Api(value = "菜单管理", tags = "菜单管理")
public class MenuInfoController {
    @Autowired
    private IMenuInfoService menuInfoService;

    /**
     * 详情
     */
    @GetMapping("/detail/{menuId}")
    @ApiOperation(value = "根据id获取详情", notes = "传入menu的id")
    public BaseResponse<MenuInfo> detail(@PathVariable String menuId) {
        BaseResponse baseResponse = new BaseResponse(BaseResponseStatus.OK);
        MenuInfo detail = menuInfoService.getById(menuId);
        baseResponse.setData(detail);
        return baseResponse;
    }

    /**
     * 新增
     */
    @PostMapping("/save")
    @ApiOperation(value = "新增菜单信息", notes = "menuInfo")
    public BaseResponse<MenuInfo> save(@RequestBody MenuInfo menuInfo) {
        BaseResponse baseResponse = new BaseResponse();
        menuInfoService.save(menuInfo);
        baseResponse.setData(menuInfo);
        return baseResponse;
    }



    /**
     * 更新
     */
    @PostMapping("/update/by/{menuId}")
    @ApiOperation(value = "更新菜单信息", notes = "menuInfo")
    public BaseResponse<MenuInfo> update(@PathVariable String menuId,@RequestBody MenuInfo menuInfo) {
        BaseResponse baseResponse = new BaseResponse();
        menuInfo.setId(menuId);
        menuInfoService.updateById(menuInfo);
        baseResponse.setData(menuInfo);
        return baseResponse;
    }

    /**
     * 根据条件查询列表信息list
     */
    @GetMapping("/list")
    @ApiOperation(value = "列表查询", notes = "menuInfo")
    public BaseResponse list(MenuInfo menuInfo) {
        BaseResponse baseResponse = new BaseResponse(BaseResponseStatus.OK);
        List<MenuInfoVO> menuInfos = menuInfoService.selectList(menuInfo);
        baseResponse.setData(menuInfos);
        return baseResponse;
    }

    /**
     * 条件查询菜单信息(分页)
     * @param menuInfoDTO
     * @return
     */
    @ApiOperation(value = "分页查询菜单信息列表", notes = "分页查询菜单信息列表")
    @ResponseBody
    @GetMapping("/page")
    public BaseResponse<PageVO<MenuInfo>> selectMenuPage(MenuInfoDTO menuInfoDTO) {
        BaseResponse baseResponse = new BaseResponse(BaseResponseStatus.OK);
        PageVO<MenuInfo> dataList = menuInfoService.selectMenuPage(menuInfoDTO);
        baseResponse.setData(dataList);
        return baseResponse;
    }

    /**
     * 批量删除菜单
     * @param menuIds
     * @return
     */
    @ApiOperation(value = "批量删除菜单", notes = "批量删除菜单")
    @ResponseBody
    @PostMapping("/delete")
    public BaseResponse deleteMenu(@RequestBody List<String> menuIds) {
        menuInfoService.removeByIds(menuIds);
        return new BaseResponse();
    }
}
